//
//  SongBySingerViewController.m
//  NhomThuy02
//
//  Created by Nguyễn Hoàng Dũng on 2/2/15.
//  Copyright (c) 2015 LamQuoc. All rights reserved.
//

#import "SongBySingerViewController.h"
#import "ManagerData.h"
#import "SongBySingerCell.h"
#import "SongDetailViewController.h"
@interface SongBySingerViewController ()<UITableViewDataSource,UITableViewDelegate>

@end

@implementation SongBySingerViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.songList = [[ManagerData defaultManager]getSongListBySingerID:[self.singer objectForKey:@"singer-id"]];
    self.tbSongList.delegate = self;
    self.tbSongList.dataSource = self;
    self.navigationItem.title = [self.singer objectForKey:@"singer-name"];
}
- (void)viewWillAppear:(BOOL)animated{
    UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 150, 30)];
    title.text=[self.singer objectForKey:@"singer-name"];
   // self.navigationItem.title = [self.singer objectForKey:@"singer-name"];
    [title setTextColor:[UIColor whiteColor]];
    //[title setBackgroundColor:[UIColor blueColor]];
    [title setTextAlignment:NSTextAlignmentCenter];
    self.navigationItem.titleView = title;
    [self.tabBarController.tabBar setHidden:YES];
    self.navigationController.navigationBar.topItem.title=@"Trở về";
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - Table
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *cellID=@"song_cell_id";
    SongBySingerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if(!cell){
        [tableView registerClass:[SongBySingerCell class] forCellReuseIdentifier:cellID];
    }
    NSDictionary *song = self.songList[indexPath.row];
    cell.lbSongID.text = [song objectForKey:@"song-code"];
    cell.lbSongName.text = [[song objectForKey:@"song-name"]capitalizedString];
    cell.lbSongLyric.text = [song objectForKey:@"lyrics"];
    [cell.lbSongID setBackgroundColor:[UIColor greenLightColor]];
    return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.songList.count;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 80;
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
     NSIndexPath* indexPath = [self.tbSongList indexPathForSelectedRow];
    
     NSDictionary* dictionary = self.songList[indexPath.row];
    
    ((SongDetailViewController*)segue.destinationViewController).songData = dictionary;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
